﻿namespace System.Collections
{
    using System.Collections.Generic;
    using System.Linq;

    public class NameValueCollection : List<KeyValuePair<string, string>>
    {
        public IEnumerable<string> AllKeys
        {
            get
            {
                NameValueCollection nameValueCollection = this;
                return nameValueCollection.Select<KeyValuePair<string, string>, string>((KeyValuePair<string, string> pair) => pair.Key);
            }
        }

        public string this[int index]
        {
            get
            {
                KeyValuePair<string, string> item = base[index];
                return item.Value;
            }
        }

        public string this[string name]
        {
            get
            {
                KeyValuePair<string, string> keyValuePair = this.SingleOrDefault<KeyValuePair<string, string>>((KeyValuePair<string, string> kv) => kv.Key.Equals(name));
                return keyValuePair.Value;
            }
        }

        public NameValueCollection()
        {
        }

        public NameValueCollection(int capacity)
            : base(capacity)
        {
        }

        public void Add(string name, string value)
        {
            base.Add(new KeyValuePair<string, string>(name, value));
        }
    }

}

namespace System.Web
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Text;
    using System.Globalization;

    public sealed class HttpUtility
    {
        private static Dictionary<string, string> entities;

        private readonly static object lock_;

        private readonly static char[] hexChars;

        private static Dictionary<string, string> Entities
        {
            get
            {
                Dictionary<string, string> strs;
                lock (HttpUtility.lock_)
                {
                    if (HttpUtility.entities == null)
                    {
                        HttpUtility.InitEntities();
                    }
                    strs = HttpUtility.entities;
                }
                return strs;
            }
        }

        static HttpUtility()
        {
            HttpUtility.lock_ = new object();
            HttpUtility.hexChars = "0123456789abcdef".ToCharArray();
        }

        public HttpUtility()
        {
        }

        private static int GetChar(byte[] bytes, int offset, int length)
        {
            int num = 0;
            int num1 = length + offset;
            int num2 = offset;
            while (num2 < num1)
            {
                int num3 = HttpUtility.GetInt(bytes[num2]);
                if (num3 != -1)
                {
                    num = (num << 4) + num3;
                    num2++;
                }
                else
                {
                    return -1;
                }
            }
            return num;
        }

        private static int GetChar(string str, int offset, int length)
        {
            int num = 0;
            int num1 = length + offset;
            int num2 = offset;
            while (num2 < num1)
            {
                char chr = str[num2];
                if (chr <= '\u007F')
                {
                    int num3 = HttpUtility.GetInt((byte)chr);
                    if (num3 != -1)
                    {
                        num = (num << 4) + num3;
                        num2++;
                    }
                    else
                    {
                        return -1;
                    }
                }
                else
                {
                    return -1;
                }
            }
            return num;
        }

        private static char[] GetChars(MemoryStream b, Encoding e)
        {
            return e.GetChars(b.GetBuffer(), 0, (int)b.Length);
        }

        private static int GetInt(byte b)
        {
            char chr = (char)b;
            if (chr < '0' || chr > '9')
            {
                if (chr < 'a' || chr > 'f')
                {
                    if (chr < 'A' || chr > 'F')
                    {
                        return -1;
                    }
                    else
                    {
                        return chr - 65 + 10;
                    }
                }
                else
                {
                    return chr - 97 + 10;
                }
            }
            else
            {
                return chr - 48;
            }
        }

        public static void HtmlAttributeEncode(string s, TextWriter output)
        {
            output.Write(HttpUtility.HtmlAttributeEncode(s));
        }

        public static string HtmlAttributeEncode(string s)
        {
            if (s != null)
            {
                bool flag = false;
                int num = 0;
                while (num < s.Length)
                {
                    if (s[num] == '&' || s[num] == '\"' || s[num] == '<')
                    {
                        flag = true;
                        break;
                    }
                    else
                    {
                        num++;
                    }
                }
                if (flag)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    int length = s.Length;
                    for (int i = 0; i < length; i++)
                    {
                        char chr = s[i];
                        if (chr == '\"')
                        {
                            stringBuilder.Append("&quot;");
                        }
                        else
                        {
                            if (chr == '&')
                            {
                                stringBuilder.Append("&amp;");
                            }
                            else
                            {
                                if (chr == '<')
                                {
                                    stringBuilder.Append("&lt;");
                                }
                                else
                                {
                                    stringBuilder.Append(s[i]);
                                }
                            }
                        }
                    }
                    return stringBuilder.ToString();
                }
                else
                {
                    return s;
                }
            }
            else
            {
                return null;
            }
        }

        public static string HtmlDecode(string s)
        {
            int num;
            if (s != null)
            {
                if (s.IndexOf('&') != -1)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    StringBuilder stringBuilder1 = new StringBuilder();
                    int length = s.Length;
                    int num1 = 0;
                    int num2 = 0;
                    bool flag = false;
                    for (int i = 0; i < length; i++)
                    {
                        char chr = s[i];
                        if (num1 != 0)
                        {
                            if (chr != '&')
                            {
                                if (num1 != 1)
                                {
                                    if (num1 != 2)
                                    {
                                        if (num1 == 3)
                                        {
                                            if (chr != ';')
                                            {
                                                if (!char.IsDigit(chr))
                                                {
                                                    num1 = 2;
                                                    if (flag)
                                                    {
                                                        stringBuilder.Append(num2.ToString(CultureInfo.InvariantCulture));
                                                        flag = false;
                                                    }
                                                    stringBuilder.Append(chr);
                                                }
                                                else
                                                {
                                                    num2 = num2 * 10 + chr - 48;
                                                    flag = true;
                                                }
                                            }
                                            else
                                            {
                                                if (num2 <= 65535)
                                                {
                                                    stringBuilder1.Append((ushort)num2);
                                                }
                                                else
                                                {
                                                    stringBuilder1.Append("&#");
                                                    stringBuilder1.Append(num2.ToString(CultureInfo.InvariantCulture));
                                                    stringBuilder1.Append(";");
                                                }
                                                num1 = 0;
                                                stringBuilder.Length = 0;
                                                flag = false;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        stringBuilder.Append(chr);
                                        if (chr == ';')
                                        {
                                            string str = stringBuilder.ToString();
                                            if (str.Length > 1 && HttpUtility.Entities.ContainsKey(str.Substring(1, str.Length - 2)))
                                            {
                                                str = HttpUtility.Entities[str.Substring(1, str.Length - 2)].ToString();
                                            }
                                            stringBuilder1.Append(str);
                                            num1 = 0;
                                            stringBuilder.Length = 0;
                                        }
                                    }
                                }
                                else
                                {
                                    if (chr != ';')
                                    {
                                        num2 = 0;
                                        if (chr != '#')
                                        {
                                            num = 2;
                                        }
                                        else
                                        {
                                            num = 3;
                                        }
                                        num1 = num;
                                        stringBuilder.Append(chr);
                                    }
                                    else
                                    {
                                        num1 = 0;
                                        stringBuilder1.Append(stringBuilder.ToString());
                                        stringBuilder1.Append(chr);
                                        stringBuilder.Length = 0;
                                    }
                                }
                            }
                            else
                            {
                                num1 = 1;
                                if (flag)
                                {
                                    stringBuilder.Append(num2.ToString(CultureInfo.InvariantCulture));
                                    flag = false;
                                }
                                stringBuilder1.Append(stringBuilder.ToString());
                                stringBuilder.Length = 0;
                                stringBuilder.Append('&');
                            }
                        }
                        else
                        {
                            if (chr != '&')
                            {
                                stringBuilder1.Append(chr);
                            }
                            else
                            {
                                stringBuilder.Append(chr);
                                num1 = 1;
                            }
                        }
                    }
                    if (stringBuilder.Length <= 0)
                    {
                        if (flag)
                        {
                            stringBuilder1.Append(num2.ToString(CultureInfo.InvariantCulture));
                        }
                    }
                    else
                    {
                        stringBuilder1.Append(stringBuilder.ToString());
                    }
                    return stringBuilder1.ToString();
                }
                else
                {
                    return s;
                }
            }
            else
            {
                throw new ArgumentNullException("s");
            }
        }

        public static void HtmlDecode(string s, TextWriter output)
        {
            if (s != null)
            {
                output.Write(HttpUtility.HtmlDecode(s));
            }
        }

        public static string HtmlEncode(string s)
        {
            if (s != null)
            {
                bool flag = false;
                int num = 0;
                while (num < s.Length)
                {
                    char chr = s[num];
                    if (chr == '&' || chr == '\"' || chr == '<' || chr == '>' || chr > '\u009F')
                    {
                        flag = true;
                        break;
                    }
                    else
                    {
                        num++;
                    }
                }
                if (flag)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    int length = s.Length;
                    for (int i = 0; i < length; i++)
                    {
                        char chr1 = s[i];
                        if (chr1 == '\"')
                        {
                            stringBuilder.Append("&quot;");
                        }
                        else
                        {
                            if (chr1 == '&')
                            {
                                stringBuilder.Append("&amp;");
                            }
                            else
                            {
                                switch (chr1)
                                {
                                    case '<':
                                        {
                                            stringBuilder.Append("&lt;");
                                            break;
                                        }
                                    case '=':
                                    Label0:
                                        {
                                            if (s[i] <= '\u009F')
                                            {
                                                stringBuilder.Append(s[i]);
                                                break;
                                            }
                                            else
                                            {
                                                stringBuilder.Append("&#");
                                                int num1 = s[i];
                                                stringBuilder.Append(num1.ToString(CultureInfo.InvariantCulture));
                                                stringBuilder.Append(";");
                                                break;
                                            }
                                        }
                                    case '>':
                                        {
                                            stringBuilder.Append("&gt;");
                                            break;
                                        }
                                    default:
                                        {
                                            goto Label0;
                                        }
                                }
                            }
                        }
                    }
                    return stringBuilder.ToString();
                }
                else
                {
                    return s;
                }
            }
            else
            {
                return null;
            }
        }

        public static void HtmlEncode(string s, TextWriter output)
        {
            if (s != null)
            {
                output.Write(HttpUtility.HtmlEncode(s));
            }
        }

        private static void InitEntities()
        {
            Dictionary<string, string> strs = new Dictionary<string, string>();
            strs.Add("nbsp", "\u00a0");
            strs.Add("iexcl", "¡");
            strs.Add("cent", "¢");
            strs.Add("pound", "£");
            strs.Add("curren", "¤");
            strs.Add("yen", "¥");
            strs.Add("brvbar", "¦");
            strs.Add("sect", "§");
            strs.Add("uml", "¨");
            strs.Add("copy", "©");
            strs.Add("ordf", "ª");
            strs.Add("laquo", "«");
            strs.Add("not", "¬");
            strs.Add("shy", "­");
            strs.Add("reg", "®");
            strs.Add("macr", "¯");
            strs.Add("deg", "°");
            strs.Add("plusmn", "±");
            strs.Add("sup2", "²");
            strs.Add("sup3", "³");
            strs.Add("acute", "´");
            strs.Add("micro", "µ");
            strs.Add("para", "¶");
            strs.Add("middot", "·");
            strs.Add("cedil", "¸");
            strs.Add("sup1", "¹");
            strs.Add("ordm", "º");
            strs.Add("raquo", "»");
            strs.Add("frac14", "¼");
            strs.Add("frac12", "½");
            strs.Add("frac34", "¾");
            strs.Add("iquest", "¿");
            strs.Add("Agrave", "À");
            strs.Add("Aacute", "Á");
            strs.Add("Acirc", "Â");
            strs.Add("Atilde", "Ã");
            strs.Add("Auml", "Ä");
            strs.Add("Aring", "Å");
            strs.Add("AElig", "Æ");
            strs.Add("Ccedil", "Ç");
            strs.Add("Egrave", "È");
            strs.Add("Eacute", "É");
            strs.Add("Ecirc", "Ê");
            strs.Add("Euml", "Ë");
            strs.Add("Igrave", "Ì");
            strs.Add("Iacute", "Í");
            strs.Add("Icirc", "Î");
            strs.Add("Iuml", "Ï");
            strs.Add("ETH", "Ð");
            strs.Add("Ntilde", "Ñ");
            strs.Add("Ograve", "Ò");
            strs.Add("Oacute", "Ó");
            strs.Add("Ocirc", "Ô");
            strs.Add("Otilde", "Õ");
            strs.Add("Ouml", "Ö");
            strs.Add("times", "×");
            strs.Add("Oslash", "Ø");
            strs.Add("Ugrave", "Ù");
            strs.Add("Uacute", "Ú");
            strs.Add("Ucirc", "Û");
            strs.Add("Uuml", "Ü");
            strs.Add("Yacute", "Ý");
            strs.Add("THORN", "Þ");
            strs.Add("szlig", "ß");
            strs.Add("agrave", "à");
            strs.Add("aacute", "á");
            strs.Add("acirc", "â");
            strs.Add("atilde", "ã");
            strs.Add("auml", "ä");
            strs.Add("aring", "å");
            strs.Add("aelig", "æ");
            strs.Add("ccedil", "ç");
            strs.Add("egrave", "è");
            strs.Add("eacute", "é");
            strs.Add("ecirc", "ê");
            strs.Add("euml", "ë");
            strs.Add("igrave", "ì");
            strs.Add("iacute", "í");
            strs.Add("icirc", "î");
            strs.Add("iuml", "ï");
            strs.Add("eth", "ð");
            strs.Add("ntilde", "ñ");
            strs.Add("ograve", "ò");
            strs.Add("oacute", "ó");
            strs.Add("ocirc", "ô");
            strs.Add("otilde", "õ");
            strs.Add("ouml", "ö");
            strs.Add("divide", "÷");
            strs.Add("oslash", "ø");
            strs.Add("ugrave", "ù");
            strs.Add("uacute", "ú");
            strs.Add("ucirc", "û");
            strs.Add("uuml", "ü");
            strs.Add("yacute", "ý");
            strs.Add("thorn", "þ");
            strs.Add("yuml", "ÿ");
            strs.Add("fnof", "ƒ");
            strs.Add("Alpha", "Α");
            strs.Add("Beta", "Β");
            strs.Add("Gamma", "Γ");
            strs.Add("Delta", "Δ");
            strs.Add("Epsilon", "Ε");
            strs.Add("Zeta", "Ζ");
            strs.Add("Eta", "Η");
            strs.Add("Theta", "Θ");
            strs.Add("Iota", "Ι");
            strs.Add("Kappa", "Κ");
            strs.Add("Lambda", "Λ");
            strs.Add("Mu", "Μ");
            strs.Add("Nu", "Ν");
            strs.Add("Xi", "Ξ");
            strs.Add("Omicron", "Ο");
            strs.Add("Pi", "Π");
            strs.Add("Rho", "Ρ");
            strs.Add("Sigma", "Σ");
            strs.Add("Tau", "Τ");
            strs.Add("Upsilon", "Υ");
            strs.Add("Phi", "Φ");
            strs.Add("Chi", "Χ");
            strs.Add("Psi", "Ψ");
            strs.Add("Omega", "Ω");
            strs.Add("alpha", "α");
            strs.Add("beta", "β");
            strs.Add("gamma", "γ");
            strs.Add("delta", "δ");
            strs.Add("epsilon", "ε");
            strs.Add("zeta", "ζ");
            strs.Add("eta", "η");
            strs.Add("theta", "θ");
            strs.Add("iota", "ι");
            strs.Add("kappa", "κ");
            strs.Add("lambda", "λ");
            strs.Add("mu", "μ");
            strs.Add("nu", "ν");
            strs.Add("xi", "ξ");
            strs.Add("omicron", "ο");
            strs.Add("pi", "π");
            strs.Add("rho", "ρ");
            strs.Add("sigmaf", "ς");
            strs.Add("sigma", "σ");
            strs.Add("tau", "τ");
            strs.Add("upsilon", "υ");
            strs.Add("phi", "φ");
            strs.Add("chi", "χ");
            strs.Add("psi", "ψ");
            strs.Add("omega", "ω");
            strs.Add("thetasym", "ϑ");
            strs.Add("upsih", "ϒ");
            strs.Add("piv", "ϖ");
            strs.Add("bull", "•");
            strs.Add("hellip", "…");
            strs.Add("prime", "′");
            strs.Add("Prime", "″");
            strs.Add("oline", "‾");
            strs.Add("frasl", "⁄");
            strs.Add("weierp", "℘");
            strs.Add("image", "ℑ");
            strs.Add("real", "ℜ");
            strs.Add("trade", "™");
            strs.Add("alefsym", "ℵ");
            strs.Add("larr", "←");
            strs.Add("uarr", "↑");
            strs.Add("rarr", "→");
            strs.Add("darr", "↓");
            strs.Add("harr", "↔");
            strs.Add("crarr", "↵");
            strs.Add("lArr", "⇐");
            strs.Add("uArr", "⇑");
            strs.Add("rArr", "⇒");
            strs.Add("dArr", "⇓");
            strs.Add("hArr", "⇔");
            strs.Add("forall", "∀");
            strs.Add("part", "∂");
            strs.Add("exist", "∃");
            strs.Add("empty", "∅");
            strs.Add("nabla", "∇");
            strs.Add("isin", "∈");
            strs.Add("notin", "∉");
            strs.Add("ni", "∋");
            strs.Add("prod", "∏");
            strs.Add("sum", "∑");
            strs.Add("minus", "−");
            strs.Add("lowast", "∗");
            strs.Add("radic", "√");
            strs.Add("prop", "∝");
            strs.Add("infin", "∞");
            strs.Add("ang", "∠");
            strs.Add("and", "∧");
            strs.Add("or", "∨");
            strs.Add("cap", "∩");
            strs.Add("cup", "∪");
            strs.Add("int", "∫");
            strs.Add("there4", "∴");
            strs.Add("sim", "∼");
            strs.Add("cong", "≅");
            strs.Add("asymp", "≈");
            strs.Add("ne", "≠");
            strs.Add("equiv", "≡");
            strs.Add("le", "≤");
            strs.Add("ge", "≥");
            strs.Add("sub", "⊂");
            strs.Add("sup", "⊃");
            strs.Add("nsub", "⊄");
            strs.Add("sube", "⊆");
            strs.Add("supe", "⊇");
            strs.Add("oplus", "⊕");
            strs.Add("otimes", "⊗");
            strs.Add("perp", "⊥");
            strs.Add("sdot", "⋅");
            strs.Add("lceil", "⌈");
            strs.Add("rceil", "⌉");
            strs.Add("lfloor", "⌊");
            strs.Add("rfloor", "⌋");
            strs.Add("lang", "〈");
            strs.Add("rang", "〉");
            strs.Add("loz", "◊");
            strs.Add("spades", "♠");
            strs.Add("clubs", "♣");
            strs.Add("hearts", "♥");
            strs.Add("diams", "♦");
            strs.Add("quot", "\"");
            strs.Add("amp", "&");
            strs.Add("lt", "<");
            strs.Add("gt", ">");
            strs.Add("OElig", "Œ");
            strs.Add("oelig", "œ");
            strs.Add("Scaron", "Š");
            strs.Add("scaron", "š");
            strs.Add("Yuml", "Ÿ");
            strs.Add("circ", "ˆ");
            strs.Add("tilde", "˜");
            strs.Add("ensp", "\u2002");
            strs.Add("emsp", "\u2003");
            strs.Add("thinsp", "\u2009");
            strs.Add("zwnj", "‌");
            strs.Add("zwj", "‍");
            strs.Add("lrm", "‎");
            strs.Add("rlm", "‏");
            strs.Add("ndash", "–");
            strs.Add("mdash", "—");
            strs.Add("lsquo", "‘");
            strs.Add("rsquo", "’");
            strs.Add("sbquo", "‚");
            strs.Add("ldquo", "“");
            strs.Add("rdquo", "”");
            strs.Add("bdquo", "„");
            strs.Add("dagger", "†");
            strs.Add("Dagger", "‡");
            strs.Add("permil", "‰");
            strs.Add("lsaquo", "‹");
            strs.Add("rsaquo", "›");
            strs.Add("euro", "€");
            HttpUtility.entities = strs;
        }

        private static bool NotEncoded(char c)
        {
            if (c == '!' || c == '\'' || c == '(' || c == ')' || c == '*' || c == '-' || c == '.')
            {
                return true;
            }
            else
            {
                return c == '\u005F';
            }
        }

        public static NameValueCollection ParseQueryString(string query)
        {
            return HttpUtility.ParseQueryString(query, Encoding.UTF8);
        }

        public static NameValueCollection ParseQueryString(string query, Encoding encoding)
        {
            if (query != null)
            {
                if (encoding != null)
                {
                    if (query.Length == 0 || query.Length == 1 && query[0] == '?')
                    {
                        return new NameValueCollection();
                    }
                    else
                    {
                        if (query[0] == '?')
                        {
                            query = query.Substring(1);
                        }
                        NameValueCollection nameValueCollection = new NameValueCollection();
                        HttpUtility.ParseQueryString(query, encoding, nameValueCollection);
                        return nameValueCollection;
                    }
                }
                else
                {
                    throw new ArgumentNullException("encoding");
                }
            }
            else
            {
                throw new ArgumentNullException("query");
            }
        }

        internal static void ParseQueryString(string query, Encoding encoding, NameValueCollection result)
        {
            string str;
            if (query.Length != 0)
            {
                string str1 = HttpUtility.HtmlDecode(query);
                int length = str1.Length;
                int num = 0;
                bool flag = true;
                while (num <= length)
                {
                    int num1 = -1;
                    int length1 = -1;
                    for (int i = num; i < length; i++)
                    {
                        if (num1 != -1 || str1[i] != '=')
                        {
                            if (str1[i] == '&')
                            {
                                length1 = i;
                                break;
                            }
                        }
                        else
                        {
                            num1 = i + 1;
                        }
                    }
                    if (flag)
                    {
                        flag = false;
                        if (str1[num] == '?')
                        {
                            num++;
                        }
                    }
                    if (num1 != -1)
                    {
                        str = HttpUtility.UrlDecode(str1.Substring(num, num1 - num - 1), encoding);
                    }
                    else
                    {
                        str = null;
                        num1 = num;
                    }
                    if (length1 >= 0)
                    {
                        num = length1 + 1;
                    }
                    else
                    {
                        num = -1;
                        length1 = str1.Length;
                    }
                    string str2 = HttpUtility.UrlDecode(str1.Substring(num1, length1 - num1), encoding);
                    result.Add(str, str2);
                    if (num != -1)
                    {
                        continue;
                    }
                    return;
                }
                return;
            }
            else
            {
                return;
            }
        }

        public static string UrlDecode(string str)
        {
            return HttpUtility.UrlDecode(str, Encoding.UTF8);
        }

        public static string UrlDecode(string s, Encoding e)
        {
            int chr;
            if (s != null)
            {
                if (s.IndexOf('%') != -1 || s.IndexOf('+') != -1)
                {
                    if (e == null)
                    {
                        e = Encoding.UTF8;
                    }
                    StringBuilder stringBuilder = new StringBuilder();
                    long length = (long)s.Length;
                    MemoryStream memoryStream = new MemoryStream();
                    for (int i = 0; (long)i < length; i++)
                    {
                        if (s[i] != '%' || (long)(i + 2) >= length || s[i + 1] == '%')
                        {
                            if (memoryStream.Length > (long)0)
                            {
                                stringBuilder.Append(HttpUtility.GetChars(memoryStream, e));
                                memoryStream.SetLength((long)0);
                            }
                            if (s[i] != '+')
                            {
                                stringBuilder.Append(s[i]);
                            }
                            else
                            {
                                stringBuilder.Append(' ');
                            }
                        }
                        else
                        {
                            if (s[i + 1] != 'u' || (long)(i + 5) >= length)
                            {
                                int num = HttpUtility.GetChar(s, i + 1, 2);
                                chr = num;
                                if (num == -1)
                                {
                                    stringBuilder.Append('%');
                                }
                                else
                                {
                                    memoryStream.WriteByte((byte)chr);
                                    i = i + 2;
                                }
                            }
                            else
                            {
                                if (memoryStream.Length > (long)0)
                                {
                                    stringBuilder.Append(HttpUtility.GetChars(memoryStream, e));
                                    memoryStream.SetLength((long)0);
                                }
                                chr = HttpUtility.GetChar(s, i + 2, 4);
                                if (chr == -1)
                                {
                                    stringBuilder.Append('%');
                                }
                                else
                                {
                                    stringBuilder.Append((ushort)chr);
                                    i = i + 5;
                                }
                            }
                        }
                    }
                    if (memoryStream.Length > (long)0)
                    {
                        stringBuilder.Append(HttpUtility.GetChars(memoryStream, e));
                    }
                    return stringBuilder.ToString();
                }
                else
                {
                    return s;
                }
            }
            else
            {
                return null;
            }
        }

        public static string UrlDecode(byte[] bytes, Encoding e)
        {
            if (bytes == null)
            {
                return null;
            }
            else
            {
                return HttpUtility.UrlDecode(bytes, 0, (int)bytes.Length, e);
            }
        }

        public static string UrlDecode(byte[] bytes, int offset, int count, Encoding e)
        {
            int chr;
            if (bytes != null)
            {
                if (count != 0)
                {
                    if (bytes != null)
                    {
                        if (offset < 0 || offset > (int)bytes.Length)
                        {
                            throw new ArgumentOutOfRangeException("offset");
                        }
                        else
                        {
                            if (count < 0 || offset + count > (int)bytes.Length)
                            {
                                throw new ArgumentOutOfRangeException("count");
                            }
                            else
                            {
                                StringBuilder stringBuilder = new StringBuilder();
                                MemoryStream memoryStream = new MemoryStream();
                                int num = count + offset;
                                for (int i = offset; i < num; i++)
                                {
                                    if (bytes[i] == 37 && i + 2 < count && bytes[i + 1] != 37)
                                    {
                                        if (bytes[i + 1] != 117 || i + 5 >= num)
                                        {
                                            int chr1 = HttpUtility.GetChar(bytes, i + 1, 2);
                                            chr = chr1;
                                            if (chr1 == -1)
                                            {
                                                goto Label1;
                                            }
                                            memoryStream.WriteByte((byte)chr);
                                            i = i + 2;
                                            goto Label0;
                                        }
                                        else
                                        {
                                            if (memoryStream.Length > (long)0)
                                            {
                                                stringBuilder.Append(HttpUtility.GetChars(memoryStream, e));
                                                memoryStream.SetLength((long)0);
                                            }
                                            chr = HttpUtility.GetChar(bytes, i + 2, 4);
                                            if (chr == -1)
                                            {
                                                goto Label1;
                                            }
                                            stringBuilder.Append((ushort)chr);
                                            i = i + 5;
                                            goto Label0;
                                        }
                                    }
                                Label1:
                                    if (memoryStream.Length > (long)0)
                                    {
                                        stringBuilder.Append(HttpUtility.GetChars(memoryStream, e));
                                        memoryStream.SetLength((long)0);
                                    }
                                    if (bytes[i] != 43)
                                    {
                                        stringBuilder.Append(bytes[i]);
                                    }
                                    else
                                    {
                                        stringBuilder.Append(' ');
                                    }
                                Label0:
                                    continue;
                                }
                                if (memoryStream.Length > (long)0)
                                {
                                    stringBuilder.Append(HttpUtility.GetChars(memoryStream, e));
                                }
                                return stringBuilder.ToString();
                            }
                        }
                    }
                    else
                    {
                        throw new ArgumentNullException("bytes");
                    }
                }
                else
                {
                    return string.Empty;
                }
            }
            else
            {
                return null;
            }
        }

        public static byte[] UrlDecodeToBytes(byte[] bytes)
        {
            if (bytes == null)
            {
                return null;
            }
            else
            {
                return HttpUtility.UrlDecodeToBytes(bytes, 0, (int)bytes.Length);
            }
        }

        public static byte[] UrlDecodeToBytes(string str)
        {
            return HttpUtility.UrlDecodeToBytes(str, Encoding.UTF8);
        }

        public static byte[] UrlDecodeToBytes(string str, Encoding e)
        {
            if (str != null)
            {
                if (e != null)
                {
                    return HttpUtility.UrlDecodeToBytes(e.GetBytes(str));
                }
                else
                {
                    throw new ArgumentNullException("e");
                }
            }
            else
            {
                return null;
            }
        }

        public static byte[] UrlDecodeToBytes(byte[] bytes, int offset, int count)
        {
            if (bytes != null)
            {
                if (count != 0)
                {
                    int length = (int)bytes.Length;
                    if (offset < 0 || offset >= length)
                    {
                        throw new ArgumentOutOfRangeException("offset");
                    }
                    else
                    {
                        if (count < 0 || offset > length - count)
                        {
                            throw new ArgumentOutOfRangeException("count");
                        }
                        else
                        {
                            MemoryStream memoryStream = new MemoryStream();
                            int num = offset + count;
                            for (int i = offset; i < num; i++)
                            {
                                char chr = (char)bytes[i];
                                if (chr != '+')
                                {
                                    if (chr == '%' && i < num - 2)
                                    {
                                        int chr1 = HttpUtility.GetChar(bytes, i + 1, 2);
                                        if (chr1 != -1)
                                        {
                                            chr = (char)((ushort)chr1);
                                            i = i + 2;
                                        }
                                    }
                                }
                                else
                                {
                                    chr = ' ';
                                }
                                memoryStream.WriteByte((byte)chr);
                            }
                            return memoryStream.ToArray();
                        }
                    }
                }
                else
                {
                    return new byte[0];
                }
            }
            else
            {
                return null;
            }
        }

        public static string UrlEncode(string str)
        {
            return HttpUtility.UrlEncode(str, Encoding.UTF8);
        }

        public static string UrlEncode(string s, Encoding Enc)
        {
            if (s != null)
            {
                if (s != "")
                {
                    bool flag = false;
                    int length = s.Length;
                    int num = 0;
                    while (num < length)
                    {
                        char chr = s[num];
                        if ((chr < '0' || chr < 'A' && chr > '9' || chr > 'Z' && chr < 'a' || chr > 'z') && !HttpUtility.NotEncoded(chr))
                        {
                            flag = true;
                            break;
                        }
                        else
                        {
                            num++;
                        }
                    }
                    if (flag)
                    {
                        byte[] numArray = new byte[Enc.GetMaxByteCount(s.Length)];
                        int bytes = Enc.GetBytes(s, 0, s.Length, numArray, 0);
                        return Encoding.UTF8.GetString(HttpUtility.UrlEncodeToBytes(numArray, 0, bytes), 0, bytes);
                    }
                    else
                    {
                        return s;
                    }
                }
                else
                {
                    return "";
                }
            }
            else
            {
                return null;
            }
        }

        public static string UrlEncode(byte[] bytes)
        {
            if (bytes != null)
            {
                if ((int)bytes.Length != 0)
                {
                    return Encoding.UTF8.GetString(HttpUtility.UrlEncodeToBytes(bytes, 0, (int)bytes.Length), 0, (int)bytes.Length);
                }
                else
                {
                    return "";
                }
            }
            else
            {
                return null;
            }
        }

        public static string UrlEncode(byte[] bytes, int offset, int count)
        {
            if (bytes != null)
            {
                if ((int)bytes.Length != 0)
                {
                    return Encoding.UTF8.GetString(HttpUtility.UrlEncodeToBytes(bytes, offset, count), offset, count);
                }
                else
                {
                    return "";
                }
            }
            else
            {
                return null;
            }
        }

        private static void UrlEncodeChar(char c, Stream result, bool isUnicode)
        {
            if (c <= 'ÿ')
            {
                if (c <= ' ' || !HttpUtility.NotEncoded(c))
                {
                    if (c != ' ')
                    {
                        if (c < '0' || c < 'A' && c > '9' || c > 'Z' && c < 'a' || c > 'z')
                        {
                            if (!isUnicode || c <= '\u007F')
                            {
                                result.WriteByte(37);
                            }
                            else
                            {
                                result.WriteByte(37);
                                result.WriteByte(117);
                                result.WriteByte(48);
                                result.WriteByte(48);
                            }
                            int num = c >> '\u0004';
                            result.WriteByte((byte)HttpUtility.hexChars[num]);
                            num = c & '\u000F';
                            result.WriteByte((byte)HttpUtility.hexChars[num]);
                            return;
                        }
                        else
                        {
                            result.WriteByte((byte)c);
                            return;
                        }
                    }
                    else
                    {
                        result.WriteByte(43);
                        return;
                    }
                }
                else
                {
                    result.WriteByte((byte)c);
                    return;
                }
            }
            else
            {
                int num1 = c;
                result.WriteByte(37);
                result.WriteByte(117);
                int num2 = num1 >> 12;
                result.WriteByte((byte)HttpUtility.hexChars[num2]);
                num2 = num1 >> 8 & 15;
                result.WriteByte((byte)HttpUtility.hexChars[num2]);
                num2 = num1 >> 4 & 15;
                result.WriteByte((byte)HttpUtility.hexChars[num2]);
                num2 = num1 & 15;
                result.WriteByte((byte)HttpUtility.hexChars[num2]);
                return;
            }
        }

        public static byte[] UrlEncodeToBytes(string str)
        {
            return HttpUtility.UrlEncodeToBytes(str, Encoding.UTF8);
        }

        public static byte[] UrlEncodeToBytes(string str, Encoding e)
        {
            if (str != null)
            {
                if (str != "")
                {
                    byte[] bytes = e.GetBytes(str);
                    return HttpUtility.UrlEncodeToBytes(bytes, 0, (int)bytes.Length);
                }
                else
                {
                    return new byte[0];
                }
            }
            else
            {
                return null;
            }
        }

        public static byte[] UrlEncodeToBytes(byte[] bytes)
        {
            if (bytes != null)
            {
                if ((int)bytes.Length != 0)
                {
                    return HttpUtility.UrlEncodeToBytes(bytes, 0, (int)bytes.Length);
                }
                else
                {
                    return new byte[0];
                }
            }
            else
            {
                return null;
            }
        }

        public static byte[] UrlEncodeToBytes(byte[] bytes, int offset, int count)
        {
            if (bytes != null)
            {
                int length = (int)bytes.Length;
                if (length != 0)
                {
                    if (offset < 0 || offset >= length)
                    {
                        throw new ArgumentOutOfRangeException("offset");
                    }
                    else
                    {
                        if (count < 0 || count > length - offset)
                        {
                            throw new ArgumentOutOfRangeException("count");
                        }
                        else
                        {
                            MemoryStream memoryStream = new MemoryStream(count);
                            int num = offset + count;
                            for (int i = offset; i < num; i++)
                            {
                                HttpUtility.UrlEncodeChar((char)bytes[i], memoryStream, false);
                            }
                            return memoryStream.ToArray();
                        }
                    }
                }
                else
                {
                    return new byte[0];
                }
            }
            else
            {
                return null;
            }
        }

        public static string UrlEncodeUnicode(string str)
        {
            if (str != null)
            {
                byte[] bytes = HttpUtility.UrlEncodeUnicodeToBytes(str);
                return Encoding.UTF8.GetString(bytes, 0, (int)bytes.Length);
            }
            else
            {
                return null;
            }
        }

        public static byte[] UrlEncodeUnicodeToBytes(string str)
        {
            if (str != null)
            {
                if (str != "")
                {
                    MemoryStream memoryStream = new MemoryStream(str.Length);
                    string str1 = str;
                    for (int i = 0; i < str1.Length; i++)
                    {
                        char chr = str1[i];
                        HttpUtility.UrlEncodeChar(chr, memoryStream, true);
                    }
                    return memoryStream.ToArray();
                }
                else
                {
                    return new byte[0];
                }
            }
            else
            {
                return null;
            }
        }

        public static string UrlPathEncode(string s)
        {
            if (!string.IsNullOrEmpty(s))
            {
                MemoryStream memoryStream = new MemoryStream();
                int length = s.Length;
                for (int i = 0; i < length; i++)
                {
                    HttpUtility.UrlPathEncodeChar(s[i], memoryStream);
                }
                byte[] array = memoryStream.ToArray();
                return Encoding.UTF8.GetString(array, 0, (int)array.Length);
            }
            else
            {
                return s;
            }
        }

        private static void UrlPathEncodeChar(char c, Stream result)
        {
            if (c < '!' || c > '~')
            {
                byte[] bytes = Encoding.UTF8.GetBytes(c.ToString());
                for (int i = 0; i < (int)bytes.Length; i++)
                {
                    result.WriteByte(37);
                    int num = bytes[i] >> 4;
                    result.WriteByte((byte)HttpUtility.hexChars[num]);
                    num = bytes[i] & 15;
                    result.WriteByte((byte)HttpUtility.hexChars[num]);
                }
                return;
            }
            else
            {
                if (c != ' ')
                {
                    result.WriteByte((byte)c);
                    return;
                }
                else
                {
                    result.WriteByte(37);
                    result.WriteByte(50);
                    result.WriteByte(48);
                    return;
                }
            }
        }
    }
}
